<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回文件指针读/写的位置</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.ftell" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ftell</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">ftell</span> &mdash; <span class="dc-title">返回文件指针读/写的位置</span></p>

 </div>
 
  <div class="refsect1 description" id="refsect1-function.ftell-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ftell</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$handle</code></span>
   ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
   返回由 <code class="parameter">handle</code> 指定的文件指针的位置，也就是文件流中的偏移量。
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.ftell-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">handle</code></dt>

     <dd>

      <p class="para">
       文件指针必须是有效的，且必须指向一个通过 <span class="function"><a href="fopen.html" class="function">fopen()</a></span>
   或 <span class="function"><a href="popen.html" class="function">popen()</a></span> 成功打开的文件。在附加模式（加参数 &quot;a&quot; 打开文件）中 <span class="function"><strong>ftell()</strong></span>
   会返回未定义错误。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ftell-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the position of the file pointer referenced by
   <code class="parameter">handle</code> as an integer; i.e., its offset into the file stream.
  </p>
  <p class="para">
   如果出错，返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


  <div class="refsect1 examples" id="refsect1-function.ftell-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2808">
    <p><strong>Example #1 <span class="function"><strong>ftell()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;opens&nbsp;a&nbsp;file&nbsp;and&nbsp;read&nbsp;some&nbsp;data<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"/etc/passwd"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fgets</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">12</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;where&nbsp;are&nbsp;we&nbsp;?<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">ftell</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;11<br /><br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

 
  <div class="refsect1 seealso" id="refsect1-function.ftell-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="fopen.html" class="function" rel="rdfs-seeAlso">fopen()</a> - 打开文件或者 URL</span></li>
    <li class="member"><span class="function"><a href="popen.html" class="function" rel="rdfs-seeAlso">popen()</a> - 打开进程文件指针</span></li>
    <li class="member"><span class="function"><a href="fseek.html" class="function" rel="rdfs-seeAlso">fseek()</a> - 在文件指针中定位</span></li>
    <li class="member"><span class="function"><a href="rewind.html" class="function" rel="rdfs-seeAlso">rewind()</a> - 倒回文件指针的位置</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>